package com.money.mvp_dagger_simple.ui.activity;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.money.mvp_dagger_simple.R;
import com.money.mvp_dagger_simple.application.AppComponent;
import com.money.mvp_dagger_simple.base.BaseActivity;
import com.money.mvp_dagger_simple.presenter.ILoginPresenter;
import com.money.mvp_dagger_simple.ui.component.DaggerLoginComponent;
import com.money.mvp_dagger_simple.ui.component.LoginComponent;
import com.money.mvp_dagger_simple.ui.module.LoginActivityModule;
import com.money.mvp_dagger_simple.ui.view.LoginView;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.OnClick;

public class LoginActivity extends BaseActivity implements LoginView {


    @BindView(R.id.accountET)
    EditText accountET;
    @BindView(R.id.passwordET)
    EditText passwordET;
    @BindView(R.id.loginB)
    Button loginB;
    private LoginComponent loginComponent;

    @Inject
    ILoginPresenter presenter;

    @Override
    public int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    public void setAppComponent(AppComponent appComponent) {
        loginComponent = DaggerLoginComponent.builder().loginActivityModule(new LoginActivityModule(this, this))
                .appComponent(appComponent).build();

        loginComponent.inject(this);
    }

    @Override
    public String getAccount() {
        return accountET.getText().toString();
    }

    @Override
    public String getPassword() {
        return passwordET.getText().toString();
    }

    @Override
    public void loginSuccess() {
        Toast.makeText(this, "登录成功", Toast.LENGTH_LONG).show();
    }

    @Override
    public void loginFailure() {
        Toast.makeText(this, "登录失败", Toast.LENGTH_LONG).show();
    }

    @OnClick(R.id.loginB)
    public void onViewClicked() {
        presenter.login();
    }
}
